/*
 * @Author: sunkai@xinxinapp.cn
 * @Date: 2020-12-14 15:41:13
 * @LastEditTime: 2020-12-15 16:36:35
 * @LastEditors: sunkai@xinxinapp.cn
 * @Description: 
 * @FilePath: /fed-e-task-02-01/code/generators/app/index.js
 */
const Generator = require('yeoman-generator')

module.exports = class extends Generator {
  prompting () {
    return this.prompt([
      {
        type: 'input',
        name: 'name',
        message: 'Your project name',
        default: this.appname
      },
      {
        type: 'input',
        name: 'version',
        message: 'Your project version',
        default: '0.0.1'
      },
      {
        type: 'list',
        name: 'mode',
        message: 'please pick a preset: Default (Yarn)',
        choices: ['Yarn', 'Npm'],
        default: 'Yarn'
      }
    ])
    .then(answer => {
      this.answer = answer
    })
  }

  writing () {
    const templates = [
      '.gitignore',
      'package.json',
      'README.md',
      'public/favicon.ico',
      'public/index.html',
      'src/App.vue',
      'src/main.js',
      'src/assets/logo.png',
      'src/components/HelloWorld.vue',
    ]
    templates.forEach(item => {
      this.fs.copyTpl(
        this.templatePath(item),
        this.destinationPath(item),
        this.answer
      )
    })
  }
}